{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "输入一串正整数,升序,没有重复;输入一个数k,问缺失的第k个正整数是几?\n",
    "示例:\n",
    "输入13579 k=3 \n",
    "输出6 \n",
    "输入13579 k=6 \n",
    "输出11"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "s = [1,3,5,7,9]\n",
    "\n",
    "# def get_k(s,k):\n",
    "#     idx,t_idx=0,0\n",
    "#     for i in range(len(s)):\n",
    "#         t = s[i]-len(s[i])\n",
    "#         if t<k:\n",
    "#             idx,t_idx=i,t\n",
    "#             continue\n",
    "#         else:\n",
    "#             break\n",
    "#     if t_idxk:\n",
    "\n",
    "    \n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "11"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def get_k(s,k):\n",
    "    cnt,cnt_old=0,0\n",
    "    last_num=0\n",
    "\n",
    "    for item in s:\n",
    "        if item-last_num>1:\n",
    "            cnt=(item-last_num-1)\n",
    "            if cnt>=k:\n",
    "                return last_num+k-(cnt-item+1)\n",
    "        last_num=item\n",
    "\n",
    "    return s[-1]+k-cnt\n",
    "\n",
    "s = [1,3,5,7,9]\n",
    "get_k(s,3)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
